package com.ophelisis.common.util;

import com.ophelisis.common.consts.AESInfo;
import com.ophelisis.common.crypt.AESCipher;

public class CryptUtils {

	public static void main(String[] args) {
		
		String key = "1234";
		String enckey = "";
		String deckey = "";
		enckey = encrypt(key);
		deckey = decrypt(enckey);
		System.out.println("encrypt("+key+") ==> "+ enckey + "::"+ enckey.length() + " decrypt() ==> " + deckey );

		key = "1234567890";
		enckey = encrypt(key);
		deckey = decrypt(enckey);
		System.out.println("encrypt("+key+") ==> "+ enckey + "::"+ enckey.length() + " decrypt() ==> " + deckey );

		key = "123456789012";
		enckey = encrypt(key);
		deckey = decrypt(enckey);
		System.out.println("encrypt("+key+") ==> "+ enckey + "::"+ enckey.length() + " decrypt() ==> " + deckey );

	}
	public static String encrypt(String key) {
		AESCipher aes;
		try {
			aes = new AESCipher(AESInfo.AES_KEY, AESInfo.AES_IV, AESCipher.AES_PKCS7_PADDING);
			return aes.encrypt(key.getBytes());
		} catch (Exception e) {
			//("AESCipher(암호화) 생성 오류!", e);
			e.printStackTrace();
		}
		return key;
	}
	public static String decrypt(String encKey) {
		AESCipher aes;
		try {
			aes = new AESCipher(AESInfo.AES_KEY, AESInfo.AES_IV, AESCipher.AES_PKCS7_PADDING);
			return aes.decrypt(encKey.getBytes());
		} catch (Exception e) {
			//("AESCipher(복호화) 생성 오류!", e);
			e.printStackTrace();
		}
		return encKey;
	}
}
